/*
2022-3-13
https://leetcode-cn.com/problems/find-all-k-distant-indices-in-an-array/
*/ 
class Solution {
public:
    vector<int> findKDistantIndices(vector<int>& nums, int key, int k) {
        set<int> ans;
        int len=nums.size();
        for(int i=0;i<len;i++)
        {
            if(nums[i]==key)
            {
                for(int j=max(0,i-k);j<=min(len-1,i+k);j++)
                {
                    ans.insert(j);
                }
            }
        }
        vector<int>res;
        for(auto c:ans) res.push_back(c);
        return res;
    }
};
